﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;


/// <summary>
/// users 的摘要说明
/// </summary>
public class users :Sql 
{
    private string _id;
    private string _password;
    private string _name;
    private string _sex;
    private string _phone;
    private string _home;
    private string _qq;
    public string id
    {
        get { return _id; }
        set { _id = value; }
    }
    public string password
    {
        get { return _password; }
        set { _password = value; }
    }

    public string name
    {
        get { return _name; }
        set { _name = value; }
    }

    public string sex
    {
        get { return _sex; }
        set { _sex = value; }
    }
    public string phone
    {
        get { return _phone; }
        set { _phone = value; }
    }
    public string home
    {
        get { return _home; }
        set { _home = value; }
    }
    public string qq
    {
        get { return _qq; }
        set { _qq = value; }
    }
	public users()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    public int isExist1(users tmp)//判断车主信息是否存在
    {
        string sql = "select count(*) from 车主 where Bid='" + tmp.id + "' or Bname= '" + tmp.id + "'";
        int result = 0;
        result = tmp.ExecutScalar(sql);
        return result;
    }
    public int isExist2(users tmp)//判断车辆信息是否存在
    {
        string sql = "select count(*) from 车辆 where Cid='" + tmp.id + "' or Cname= '" + tmp.id + "'";
        int result = 0;
        result = tmp.ExecutScalar(sql);      
        return result;
    }
    public int isExist3(users tmp)//判断车辆出入信息是否存在
    {
        string sql = "select count(*) from 车辆出入 where Did='" + tmp.id + "' or Dcrid= '" + tmp.id + "'";
        int result = 0;
        result = tmp.ExecutScalar(sql);     
        return result;
    }

    public int login(users tmp)//登录
    {
        string sql = "select count(*) from 管理员 where Aid='" + tmp.id + "'and Apassword='" + tmp.password + "'";
        int result = 0;
        result = tmp.ExecutScalar(sql);
        return result;
    }
    public SqlDataReader select1(users tmp)//查询车主信息
    {
        string sql = "select * from 车主 where Bname='" + tmp.id + "'or Bid= '" + tmp.id + "'";
        SqlDataReader sqlread = tmp.ExeReader(sql);
        return sqlread;
    }
    public SqlDataReader select2(users tmp)//查询车辆信息
    {
        string sql = "select * from 车辆 where Cid='" + tmp.id + "' or Cname= '" + tmp.id + "'";
        SqlDataReader sqlread = tmp.ExeReader(sql);
        return sqlread;
    }
    public SqlDataReader select3(users tmp)//查询车辆出入信息
    {
        string sql = "select * from 车辆出入 where  Did='" + tmp.id + "'  or Dcrid= '" + tmp.id + "'";
        SqlDataReader sqlread = tmp.ExeReader(sql);
        return sqlread;
    }
    public DataSet GetALLUsers1()//显示车主表中的所有信息
    {
        string sql = "select * from 车主";
        users tmp = new users();
        DataSet ds = tmp.GetS(sql);
        return ds;
        //return tmp.GetS(sql);
    }
    public DataSet GetALLUsers2()//显示车辆表中的所有信息
    {
        string sql = "select * from 车辆";
        users tmp = new users();
        DataSet ds = tmp.GetS(sql);
        return ds;
        //return tmp.GetS(sql);
    }
    public DataSet GetALLUsers3()//显示车辆出入表中的所有信息
    {
        string sql = "select * from 车辆出入";
        users tmp = new users();
        DataSet ds = tmp.GetS(sql);
        return ds;
        //return tmp.GetS(sql);
    }
    public int add1(users tmp)//添加车主信息
    {

        string sql = "insert into 车主(Bid,Bname,Bsex,Bphone,Bhome) values('" + id + "','" + name + "','" + sex + "','" + phone  + "','"+home +"')";
        int result =
        result = tmp.ExeNonQuery(sql);
        return result;
    }
    public int add2(users tmp)//添加车辆信息
    {

        string sql = "insert into 车辆(Cid,Cname,Ccx,Ccolour,Ccid,Ctime) values('" + id + "','" + name + "','" + sex + "','" + phone + "','"+home+"','"+qq+"')";
        int result =
        result = tmp.ExeNonQuery(sql);
        return result;
    }
    public int add3(users tmp)//添加车辆出入信息
    {

        string sql = "insert into 车辆出入(Did,Dstatus,Dcrid,Dcrcx,Dname) values('" + id + "','" + name + "','" + sex + "','" + phone + "','"+home+"')";
        int result =
        result = tmp.ExeNonQuery(sql);
        return result;
    }
    public void GenXin1(users tmp)//修改车主信息
    {
        string sql = "update 车主  set Bname='" + tmp.name+ "' ,Bsex='"+tmp.sex+"' ,Bphone='"+tmp.phone+"',Bhome='"+tmp.home+"'where Bid='" + tmp.id + "'";
        //int return=tmp.ExeNonQuery (sql); 
        tmp.ExeNonQuery(sql);
    }
    public void GenXin2(users tmp)//修改车辆信息
    {
        string sql = "update 车辆  set Cname='" + tmp.name + "',Ccx='"+tmp.sex+"',Ccolour='"+tmp.phone+"',Ccid='"+tmp.home+"',Ctime='"+tmp.qq+"' where Cid='" + tmp.id + "'";
        //int return=tmp.ExeNonQuery (sql); 
        tmp.ExeNonQuery(sql);
    }
    public void GenXin3(users tmp)//修改车辆出入信息
    {
        string sql = "update 车辆出入  set Dstatus='" + tmp.name + "',Dcrid='"+tmp.sex+"',Dcrcx='"+tmp.phone+"' ,Dname='"+tmp.home+"'where Did='" + tmp.id + "'";
        //int return=tmp.ExeNonQuery (sql); 
        tmp.ExeNonQuery(sql);
    }
    public int delete1(users tmp)//删除车主信息
    {
        string sql = " delete from 车主 where Bid='" + tmp.id + "' or Bname= '" + tmp.id + "'";
        int result = 0;
        result = tmp.ExeNonQuery(sql);
        return result;
    }
    public int delete2(users tmp)//删除车辆信息
    {
        string sql = " delete from 车辆 where Cid='" + tmp.id + "' or Cname= '" + tmp.id + "'";
        int result = 0;
        result = tmp.ExeNonQuery(sql);
        return result;
    }
    public int delete3(users tmp)//删除车辆出入信息
    {
        string sql = " delete from 车辆出入 where Did='" + tmp.id + "' or Dcrid= '" + tmp.id + "'";
        int result = 0;
        result = tmp.ExeNonQuery(sql);
        return result;
    } 

}